//获取应用实例
const app = getApp();

Component({

    options: {
        styleIsolation: 'shared'
    },

    behaviors: [],

    properties: {
        value:{
            type: Number,
            value:0,
        },
        color:"#f3f3f3",
        min:{type:Number,value:0}
    },
    data: { // 私有数据，可用于模版渲染
        showInput: false,
        inputValue: 0,
    },
    attached: function () {// 在组件实例进入页面节点树时执行

    },
    observers: {//数据监听器
        // 'images': function(val) {
        //     this.setData({
        //         _images: val,
        //     })
        // },

    },
    methods: {
        decHandle(e){
            let {value, min} = this.data
            if (value > min){
                --value
                this.setData({
                    value,
                })
                this.triggerEvent('change', {
                    value,
                    handle: 'dec',
                })
            }

        },

        incHandle(e){
            let {value} = this.data
            ++value
            this.setData({
                value,
            })
            this.triggerEvent('change', {
                value,
                handle: 'inc'
            })
        },

        showInputHandle(e){
            let {value} = this.data
            this.setData({
                inputValue: value,
                showInput:true
            })
        },
        inputBlur(e){
            let num = e.detail.value
            const {min} = this.data
            if (!num){
                num = 0
            }
            if (num < min){
                num = min
            }
            this.data.inputValue = num
        },
        inputConfirmHandle(){
            let {value, inputValue} = this.data
            this.setData({
                value: inputValue,
                showInput: false
            })
            this.triggerEvent('change', {
                value:inputValue,
                handle: 'input'
            })
        }
    },
})
